/* Check JER_Bitmatrix_Dotprod(). */
#include <stdio.h>
#include "jerasure.h"
#include "reed_sol.h"

int main( int argc, char** argv )
{
	int *old_bitmatrix;
	int *inverse_matrix;
	int i, j;
	int m = atoi( argv[1] );
	int k = atoi( argv[2] );
	int w = atoi( argv[3] );
	int size;
	unsigned char* buffer;
	unsigned char** data_ptrs;
	unsigned char** coding_ptrs;

	size = 8 * w;
	
	srand48(m);
	old_bitmatrix = (int*) malloc( sizeof(int) * k*w*m*w );
	buffer = (unsigned char*) malloc( sizeof(char) * (k+m) * size );
	data_ptrs = (unsigned char**) malloc( sizeof( char* ) * k );
	coding_ptrs = (unsigned char**) malloc( sizeof( char* ) * m );
	for( i = 0; i < k * size; i++ )
	{
		buffer[i] = lrand48() % 256;
		if( i % size == 0 )
			fprintf( stdout, "\n" );
		fprintf( stdout, "%x", buffer[i] );
	}
	fprintf( stdout, "\n" );
	for( i = 0; i < k; i++ )
		data_ptrs[i] = buffer + i*size;
	for( i = 0; i < m; i++ )
		coding_ptrs[i] = buffer + k * size + i * size;

	for( j = 0; j < m*w * k*w; j++ )
		old_bitmatrix[j] = lrand48() % 2;

	for( i = 0; i < m; i++ )
		jerasure_bitmatrix_dotprod( k, w, old_bitmatrix + i*k*w*w, NULL, i+k, 
				(char**)data_ptrs, (char**)coding_ptrs, size, 8 );

	for( i = 0; i < (k+m) * size; i++ )
	{
		if( i % size == 0 )
			fprintf( stdout, "\n" );
		fprintf( stdout, "%x", buffer[i] );
	}
	fprintf( stdout, "\n" );

	return 0;
}
